{extend name="index/index"}

{block name="main"}
<div class="admin-biaogelist">

    <div class="listbiaoti am-cf">
        <ul class="am-icon-flag on">商家审核</ul>
        <dl class="" style="float: right;"> 当前位置： 首页 > <a href="#">商家列表</a></dl>
    </div>


    <form class="am-form am-g">
        <table width="100%" class="am-table am-table-bordered am-table-radius am-table-striped">
            <thead>
            <tr class="am-success">
                <th class="table-id">ID</th>
                <th class="table-type">联系人 </th>
                <th class="table-type">房名</th>
                <th class="table-type">房屋地址</th>
                <th class="table-type">房子照片</th>
                <th class="table-author">房子类型 </th>
                <th class="table-author">审核状态 </th>
                <th width="163px" class="table-set">操作</th>
            </tr>
            </thead>
            <tbody>
            {volist name="data" id="v"}
            <tr>
                <td class="good_id" good_id="{$v.id}">{$v.id}</td>
                <td>{$v.link_name}</td>
                <td>{$v.house_name}</td>
                <td>{$v.house_address}</td>
                <td class="am-hide-sm-only"><img src="/uploads/housepic/{:str_replace('\','/',$v.house_pic)}" width="100px" height="50px"></td>
                <td class="am-hide-sm-only">{if condition="$v.housetype eq 41 "}别墅
                    {elseif condition="$v.housetype eq 42 "  /} 宾馆
                    {else /}民房
                    {/if}</td>
                <td class="am-hide-sm-only updateaudit">{if condition="$v.checking eq 0 "}待审核
                    {elseif condition="$v.checking eq 1 " /} 审核通过
                    {else /}未通过审核
                    {/if}</td>
                <td><div class="am-btn-toolbar">
                    <div class="am-btn-group am-btn-group-xs">
                        <button data-id="{$v.id}" static_id="{$v.checking}" type="button" class="am-btn am-btn-default am-btn-xs am-text-secondary am-round" data-toggle="modal" data-target=".bs-example-modal-sm" onclick="clicks(this)">修改状态</button>
                    </div>
                </div>
                </td>
            </tr>
            {/volist}
            </tbody>
        </table>
    </form>
    <ul class="am-pagination am-fr">
        {$data->render()}
    </ul>
</div>


<!-- 修改状态 小模态框 -->

<div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
    <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content" >
            <div style="margin-left:10%;">
                <h4>修改状态</h4>
                <hr/>
                <form class="myform">
                    <input type="radio" name="checking" value="0"> 待审核
                    <input type="radio" name="checking" value="1"> 审核通过
                    <input type="radio" name="checking" value="2"> 审核不通过
                    <br/>
                    <button type="button" class="btn btn-default goodupdate" data-dismiss="modal">确认修改</button>
                </form>
            </div>
        </div>
    </div>
</div>
<script>
    function clicks(t) {
        var id = $(t).attr('data-id');
        var static_id = $(t).attr('static_id');
        var button = $('.myform button[type="button"]');
        var radio = $('.myform input[type="radio"]');

        for(var i=0; i<radio.length; i++) {
            if ($(radio[i]).val() == static_id) {
                $(radio[i]).attr("checked",true);
                button.attr('good_id',id);
            }
        }

    }
    $('.goodupdate').click(function(){
        var id = $(this).attr('good_id');
        var checking = $("input[type='radio']:checked").val();
        $.ajax({
            url : '/admin/houseajax',
            type : 'post',
            dateType : 'json',
            data : {'id':id,'checking':checking},
            success : function(data){

                if(data){
                    $(".good_id").each(function () {

                        if ($(this).attr('good_id') == id) {

                            switch(checking) {
                                case '0':
                                    $($(this).parents("tr").children('.updateaudit')[0]).html('待审核');
                                    break;
                                case '1':
                                    $($(this).parents("tr").children('.updateaudit')[0]).html('审核通过');
                                    break;
                                case '2':
                                    $($(this).parents("tr").children('.updateaudit')[0]).html('未通过审核');
                                    break;

                            }
                        }
                    });
                }else{
                    alert('审核失败请重试');
                }
            },
            error : function(){
                alert('ajax执行失败');
            }

        })

    })
</script>
{/block}
